﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WT.Sockert.Interfaces;

namespace WT.Sockert.Heads {
    class SocketParser : ISocketParser {

        public Action<List<byte>> ReceiveData = delegate { };
        public Func<string, byte[]> TextFrame = x => new byte[0];
        public Func<byte[], byte[]> BinaryFrame = x => new byte[0];

        private readonly List<byte> _data = new List<byte>();
        public byte[] FrameBinary(byte[] bytes) {
            return BinaryFrame(bytes);
        }

        public byte[] FrameText(string text) {
            return TextFrame(text);
        }

        public void Receive(IEnumerable<byte> data) {
            _data.AddRange(data);

            ReceiveData(_data);
        }
    }
}
